# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Maxwell Pray a.k.a. Synthead <synthead@gmail.com>

pkgbase=guvcview
pkgname=(guvcview guvcview-common guvcview-qt)
pkgver=2.0.8
pkgrel=3
pkgdesc='Simple interface for capturing and viewing video from v4l2 devices'
arch=('loong64' 'x86_64')
url='http://guvcview.sourceforge.net/'
license=('GPL3')
depends=('ffmpeg' 'gsl' 'gtk3' 'qt5-base' 'portaudio')
makedepends=('intltool')
options=('!emptydirs')
source=("https://downloads.sourceforge.net/$pkgbase/$pkgbase-src-$pkgver.tar.bz2")
sha256sums=('a21f4e448286666cf27bafef5290cc953a0a1796b752e5bbe521266dc1230c81')
noextract=($pkgbase-src-$pkgver-2.tar.bz2) # missing root dir

prepare() {
  cp -a $pkgbase{-src-$pkgver,-qt}
}

build() {
  # GTK+ version
  cd $pkgbase-src-$pkgver
  ./configure --prefix=/usr --disable-debian-menu
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make

  # Qt version
  cd ../$pkgbase-qt
  ./configure --prefix=/usr --disable-debian-menu --disable-gtk3 --enable-qt5
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package_guvcview-common() {
  pkgdesc="Common files for guvcview"
  depends=('ffmpeg' 'gsl' 'libusb' 'portaudio')

  cd $pkgbase-src-$pkgver
  make DESTDIR="$pkgdir" install
  make -C guvcview DESTDIR="$pkgdir" uninstall
  make -C data DESTDIR="$pkgdir" uninstall-man1 uninstall-appdataDATA uninstall-desktopDATA
  install -Dm644 data/icons/guvcview.png "$pkgdir"/usr/share/icons/hicolor/128x128/apps/guvcview.png
}

package_guvcview() {
  pkgdesc="Simple GTK+ interface for capturing and viewing video from v4l2 devices"
  depends=('guvcview-common' 'gtk3')

  cd $pkgbase-src-$pkgver
  make -C guvcview DESTDIR="$pkgdir" install
  make -C data DESTDIR="$pkgdir" install-man1 install-appdataDATA install-desktopDATA
  sed -i 's/^Icon=.*/Icon=guvcview/' "$pkgdir"/usr/share/applications/guvcview.desktop
}

package_guvcview-qt() {
  pkgdesc="Simple Qt interface for capturing and viewing video from v4l2 devices"
  depends=('guvcview-common' 'qt5-base')

  cd $pkgbase-qt
  make -C guvcview DESTDIR="$pkgdir" install
  make -C data DESTDIR="$pkgdir" install-man1 install-appdataDATA install-desktopDATA
  mv "$pkgdir"/usr/bin/guvcview{,-qt}
  mv "$pkgdir"/usr/share/man/man1/guvcview{,-qt}.1
  mv "$pkgdir"/usr/share/applications/guvcview{,-qt}.desktop
  sed -i 's/Exec=guvcview/Exec=guvcview-qt/
          s/^Icon=.*/Icon=guvcview/' "$pkgdir"/usr/share/applications/guvcview-qt.desktop
  mv "$pkgdir"/usr/share/metainfo/guvcview{,-qt}.appdata.xml
  sed -i 's/net.sourceforge.guvcview/net.sourceforge.guvcview-qt/
          s/guvcview.desktop/guvcview-qt.desktop/' "$pkgdir"/usr/share/metainfo/guvcview-qt.appdata.xml
}
